// run: $exec < input
#include <cstdio>
#include <vector>

int const maxn = 100007;
int has_cat[maxn];
int conc_cat[maxn];
int n, m, ans;

std::vector<int> tree[maxn];

void dfs(int u, int p)
{
	conc_cat[u] = (has_cat[u]) ? conc_cat[p] + 1 : 0;
	if (conc_cat[u] > m) return;
	bool is_leaf = true;
	for (int i = 0; i < (int)tree[u].size(); i++) {
		int v = tree[u][i];
		if (v == p) continue;
		is_leaf = false;
		dfs(v, u);
	}
	if (is_leaf) ans++;
}

int main()
{
	std::scanf("%d %d", &n, &m);
	for (int i = 1; i <= n; i++) std::scanf("%d", &has_cat[i]);
	for (int i = 1, x, y; i < n; i++) {
		std::scanf("%d %d", &x, &y);
		tree[x].push_back(y);
		tree[y].push_back(x);
	}
	dfs(1, 0);
	std::printf("%d\n", ans);
}

